home *** CD-ROM | disk | FTP | other *** search
/ Amoszine PD Edition 0 / Amoszine PD Edition 0.adf / SOURCE_CODE / word_counter.AMOS / word_counter.amosSourceCode
AMOS Source Code  |  1993-02-25  |  2KB  |  92 lines

  1. '
  2. ' Text Utilities #1 - Word Counter 
  3. ' (c) 1990 Jason D Banks 
  4. '
  5. _LED_OFF
  6. F$=Fsel$("","","Name Text File to","Count Words In")
  7. ' get filename 
  8. If F$="" Then Edit 
  9. _GETDATA[F$]
  10. ' find size of file
  11. SIZE=Param
  12. '
  13. _LOADFILE[F$,SIZE]
  14. POS=Start(15)
  15. FINIS=POS+SIZE
  16. WORDS=0
  17. ' load file into memory
  18. While POS<FINIS
  19.    _GET_WORD
  20.    Inc WORDS
  21.    _LED_TOGGLE
  22.    ' count words
  23. Wend 
  24. ' _LED_TOGGLE is used, so that it can be shown that the computer is
  25. ' still working, and has not crashed...
  26. Print "Number of words in ";NAME$
  27. Print "is ";WORDS
  28. _LED_ON
  29. '
  30. ' procedures from here 
  31. '
  32. Procedure _GET_WORD
  33.    Shared POS,FINIS
  34.    VC$="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  35.    CH$=Upper$(Chr$(Peek(POS)))
  36.    While Instr(VC$,CH$)=0 : Inc POS : CH$=Upper$(Chr$(Peek(POS))) : Wend 
  37.    If POS>FINIS Then Pop Proc
  38.    While Instr(VC$,CH$)>0 : Inc POS : CH$=Upper$(Chr$(Peek(POS))) : Wend 
  39.    If POS>FINIS Then Pop Proc
  40.    While Instr(VC$,CH$)=0 : Inc POS : CH$=Upper$(Chr$(Peek(POS))) : Wend 
  41.    If POS>FINIS Then Pop Proc
  42.    ' reads in a word and then exits 
  43. End Proc
  44. Procedure _GETDATA[NAME$]
  45.    Erase 15
  46.    Reserve As Work 15,260
  47.    Dreg(1)=Varptr(NAME$) : Dreg(2)=-2
  48.    HANDLE=Doscall(-84)
  49.    If HANDLE=0 Then Pop Proc
  50.    Dreg(1)=HANDLE
  51.    Dreg(2)=Start(15)
  52.    WORKS=Doscall(-102)
  53.    If WORKS=0 Then Dreg(1)=HANDLE : DUMMY=Doscall(-90) : Pop Proc
  54.    LGTH=Leek(Start(15)+124)
  55.    Dreg(1)=HANDLE
  56.    DUMMY=Doscall(-90)
  57.    Erase 15
  58.    ' RETURNS THE SIZE OF FILE NAME$ IN PARAM
  59.    ' NOTE THAT BANK 15 IS USED
  60. End Proc[LGTH]
  61. Procedure _LOADFILE[NAME$,LGTH]
  62.    Erase 15
  63.    Reserve As Work 15,LGTH
  64.    Dreg(1)=Varptr(NAME$)
  65.    Dreg(2)=1005
  66.    HANDLE=Doscall(-30)
  67.    ' = open file for reading
  68.    Dreg(1)=HANDLE
  69.    Dreg(2)=Start(15)
  70.    Dreg(3)=LGTH
  71.    RDIN=Doscall(-42)
  72.    ' = read in file contents
  73.    Dreg(1)=HANDLE
  74.    DUMMY=Doscall(-36)
  75.    ' = close file down
  76.    '
  77.    ' loads the entire file into bank 15 
  78. End Proc
  79. Procedure _LED_OFF
  80.    Poke 12574721,Peek(12574721) or 2
  81. End Proc
  82. Procedure _LED_ON
  83.    Poke 12574721,Peek(12574721) and 253
  84. End Proc
  85. Procedure _LED_TOGGLE
  86.    A=Peek(12574721)
  87.    If(A and 2)=2
  88.       _LED_ON
  89.    Else 
  90.       _LED_OFF
  91.    End If 
  92. End Proc